<!DOCTYPE html>

<html>
<head>
	<title>AIL-Framework</title>
	<link rel="icon" href="{{ url_for('static', filename='image/ail-icon.png')}}">
	<!-- Core CSS -->
	<link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">

	<!-- JS -->
	<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
  <script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
  <script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>

</head>

<body>

	{% include 'nav_bar.html' %}

	<div class="container-fluid">
		<div class="row">

			{% include 'settings/menu_sidebar.html' %}

			<div class="col-12 col-lg-10" id="core_content">

				<div class="card">
					<div class="card-header bg-dark text-white">
						<span class="badge badge-pill badge-light flex-row-reverse float-right">
							{% if server_metadata['ping'] %}
								<div style="color:Green;">
									<i class="fas fa-check-circle fa-2x"></i>
									PING
								</div>
							{% else %}
								<div style="color:Red;">
									<i class="fas fa-times-circle fa-2x"></i>
									ERROR
								</div>
							{% endif %}
						</span>
						<h5 class="card-title">{{server_metadata['uuid']}}</h5>
					</div>
					<div class="card-body">
						<table class="table table-borderless">
							<tbody>
								<tr>
									<td class="text-right"><b>URL</b></td>
									<td>
										{{server_metadata['url']}}
										{% if server_metadata['ping'] %}
											<span style="color:Green;">
												<i class="fas fa-check-circle"></i>
											</span>
										{% else %}
											<span style="color:Red;">
												<i class="fas fa-times-circle"></i>
											</span>
										{% endif %}
										<div>
											<a href="{{ url_for('ail_2_ail_sync.ail_server_api_ping') }}?uuid={{server_metadata['uuid']}}">
												<button type="button" class="btn btn-primary px-1 py-0">
													<i class="fas fa-redo-alt"></i> ping
												</button>
											</a>
										</div>
									</td>
								</tr>
								<tr>
									<td class="text-right"><b>Api Key</b></td>
									<td>
										{{server_metadata['api_key']}}
										<input id="api_key" name="api_key" type="text" value="{{ server_metadata['api_key'] }}" hidden>
										<button type="button" class="btn btn-secondary px-2 py-0" onclick="copy_api_key()">
											<i class="fas fa-clipboard"></i>
										</button>
									</td>
								</tr>
								<tr>
									<td class="text-right"><b>Description</b></td>
									<td>
										{{server_metadata['description']}}
									</td>
								</tr>
								<!-- <tr>
									<td class="text-right"><b>Pull</b></td>
									<td>
										{% if server_metadata['pull'] %}
											<span style="color:Green;">
												<i class="fas fa-check-circle"></i> Enabled
											</span>
										{% else %}
											<span class="text-secondary">
												<i class="fas fa-times-circle"></i> Disabled
											</span>
										{% endif %}
									</td>
								</tr> -->
								<tr>
									<td class="text-right"><b>Push</b></td>
									<td>
										{% if server_metadata['push'] %}
											<span style="color:Green;">
												<i class="fas fa-check-circle"></i> Enabled
											</span>
										{% else %}
											<span class="text-secondary">
												<i class="fas fa-times-circle"></i> Disabled
											</span>
										{% endif %}
									</td>
								</tr>
								<tr>
									<td class="text-right"><b>Version</b></td>
									<td>
										{{server_metadata['version']}}
										<a href="{{ url_for('ail_2_ail_sync.ail_server_api_version') }}?uuid={{server_metadata['uuid']}}">
											<button type="button" class="btn btn-info px-1 py-0">
												<i class="fas fa-redo-alt"></i>
											</button>
										</a>
									</td>
								</tr>
								<tr>
									<td class="text-right"><b>AIL Sync</b></td>
									<td>
										{% if server_metadata['server_sync_mode']['api'] %}
	                  	API
	                  {% endif %}
										{% if server_metadata['server_sync_mode']['pull'] %}
	                  	PULL
	                  {% endif %}
										{% if server_metadata['server_sync_mode']['push'] %}
	                  	PUSH

											<a href="{{ url_for('ail_2_ail_sync.ail_server_sync_client_kill') }}?uuid={{ server_metadata['uuid'] }}">
												<button type="button" class="btn btn-danger px-1 py-0">
													<i class="fas fa-times"></i> Kill
												</button>
											</a>
											<a href="{{ url_for('ail_2_ail_sync.ail_server_sync_client_relaunch') }}?uuid={{ server_metadata['uuid'] }}">
												<button type="button" class="btn btn-info px-1 py-0">
													<i class="fas fa-redo-alt"></i> reLaunch
												</button>
											</a>
										{% else %}
											{% if (server_metadata['pull'] or server_metadata['push']) and server_metadata['sync_queues']%}
												<a href="{{ url_for('ail_2_ail_sync.ail_server_sync_client_launch') }}?uuid={{ server_metadata['uuid'] }}">
													<button type="button" class="btn btn-primary px-1 py-0">
														<i class="fas fa-play"></i> Launch
													</button>
												</a>
											{% endif %}
	                  {% endif %}
									</td>
								</tr>
								<tr>
									<td class="text-right"><b>Remote Sync</b></td>
									<td>
										{% if server_metadata['client_sync_mode']['api'] %}
	                  	API
	                  {% endif %}
										{% if server_metadata['client_sync_mode']['pull'] %}
	                  	PULL
	                  {% endif %}
										{% if server_metadata['client_sync_mode']['push'] %}
	                  	PUSH
	                  {% endif %}

										{% if server_metadata['client_sync_mode']['api'] or server_metadata['client_sync_mode']['pull'] or server_metadata['client_sync_mode']['push'] %}
											<a href="{{ url_for('ail_2_ail_sync.ail_server_client_kill') }}?uuid={{ server_metadata['uuid'] }}">
		 										 <button type="button" class="btn btn-danger px-1 py-0">
		 											 <i class="fas fa-times"></i> kill
		 										 </button>
		 									 </a>
									 	{% endif %}
									</td>
								</tr>
							</tbody>
						</table>

						{% if server_metadata['error']%}
<pre class="bg-dark text-white">
					----------------------------
					-          ERROR           -
					----------------------------
{{server_metadata['error']}}
</pre>
						{% endif %}

						<div class="my-4">
							<a href="{{ url_for('ail_2_ail_sync.ail_server_delete') }}?uuid={{server_metadata['uuid']}}">
								<button type="button" class="btn btn-danger">
									<i class="fas fa-trash-alt"></i> <b>Delete AIL Server</b>
								</button>
							</a>
							<a href="{{ url_for('ail_2_ail_sync.ail_server_edit') }}?uuid={{server_metadata['uuid']}}">
								<button type="button" class="btn btn-info">
									<i class="fas fa-pencil-alt"></i> <b>Edit</b>
								</button>
							</a>
						</div>

						<div class="card">
							<div class="card-header bg-secondary text-white">
								<h6 class="card-title"><b>SYNC QUEUES:</b></h6>
							</div>
							<div class="card-body">

								<a href="{{ url_for('ail_2_ail_sync.ail_server_sync_queues') }}?uuid={{ server_metadata['uuid'] }}">
									<button type="button" class="btn btn-primary my-4">
										<i class="fas fa-plus"></i> <b>Register Sync Queue</b>
									</button>
								</a>

								<table id="table_sync_queues" class="table table-striped border-primary">
				          <thead class="bg-dark text-white">
				            <tr>
												<th>name</th>
				                <th>uuid</th>
				                <th>description</th>
				                <th>max size</th>
												<th>Unregister Queue</th>
				            </tr>
				          </thead>
				          <tbody style="font-size: 15px;">
				            {% for dict_queue in server_metadata['sync_queues'] %}
				              <tr class="border-color: blue;">
												<td>{{ dict_queue['name']}}</td>
				                <td>
													<a href="{{ url_for('ail_2_ail_sync.sync_queue_view') }}?uuid={{ dict_queue['uuid'] }}">
														{{ dict_queue['uuid']}}
													</a>
													<div>
														{% for tag in dict_queue['tags'] %}
															<span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }} pull-left">{{ tag }}</span>
														{% endfor %}
													</div>
												</td>
				                <td>{{ dict_queue['description']}}</td>
												<td>{{ dict_queue['max_size']}}</td>
												<td class="text-right">
													<a href="{{ url_for('ail_2_ail_sync.ail_server_sync_queues_unregister') }}?ail_uuid={{ server_metadata['uuid'] }}&queue_uuid={{ dict_queue['uuid'] }}">
														<button type="button" class="btn btn-danger"><i class="fas fa-trash-alt"></i></button>
													</a>
												</td>
				              </tr>
				            {% endfor %}
				          </tbody>
				        </table>


					</div>


				</div>
			</div>


		</div>

	</div>

</body>

<script>
$(document).ready(function(){
	$('#nav_sync').removeClass("text-muted");

  $('#table_sync_queues').DataTable({
        "aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
        "iDisplayLength": 10,
        "order": [[ 0, "asc" ]]
  });

});

function copy_api_key() {
	api_key = $('#api_key').val();
	navigator.clipboard.writeText(api_key);
}

function toggle_sidebar(){
	if($('#nav_menu').is(':visible')){
		$('#nav_menu').hide();
		$('#side_menu').removeClass('border-right')
		$('#side_menu').removeClass('col-lg-2')
		$('#core_content').removeClass('col-lg-10')
	}else{
		$('#nav_menu').show();
		$('#side_menu').addClass('border-right')
		$('#side_menu').addClass('col-lg-2')
		$('#core_content').addClass('col-lg-10')
	}
}

</script>
